<template>
  <div class="styleBar">
    <div class="item" v-for="(b, i) in blocks" :key="i">
      <div class="b2" :style="{width: b+'%'}"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "StyleBar",
  props: {
    val: {
      type: Number,
      required: true
    },
    sum: {
      type: Number,
      default: 100
    }
  },
  data () {
    const length = 10;
    var blocks = new Array(length).fill(0);
    var each = this.sum / length;
    var full = Math.floor(this.val / each);
    var mod = this.val % each;
    for (let i = 0; i < length; i++) {
      if (i < full) {
        blocks[i] = 100;
      } else if (i == full) {
        blocks[i] = mod / each * 100;
      } else {
        blocks[i] = 0; 
      }
    }
    return {
      blocks
    };
  }
};
</script>
<style lang="scss" scoped>
.styleBar {
  display: flex;
  width: 600px;
  justify-content: space-around;
  .item {
    background: white;
    height: 44px;
    width: 50px;
    .b2 {
      height: 44px;
      background: #7dd6ff;
    }
  }
}
</style>
